package com.itheima.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
//@WebFilter(urlPatterns = "/*")//拦截所有
public class DemoFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        //初始化方法,只会调用一次:服务器启动,Filter实例创建之后调用
        log.info("DemoFilter init.....");
    }

        //每次拦截到请求后调用,会调用多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("拦截到了请求,doFilter运行.....");
        //放行
        filterChain.doFilter(servletRequest,servletResponse);
    }

    //初始化方法,只会调用一次:服务器关闭时调用
    @Override
    public void destroy() {
        log.info("DemoFilter destroy.....");
    }
}
